package com.example.room.repository;

import androidx.lifecycle.LiveData;

import com.blankj.subutil.util.PinyinUtils;
import com.blankj.utilcode.util.LogUtils;
import com.example.room.entity.User;
import com.example.room.dao.UserDao;
import com.example.room.UserWithOrders;

import java.util.List;

// 在 UserRepository 或其他适当的位置
public class UserRepository {

    private final UserDao userDao;

    public UserRepository(UserDao userDao) {
        this.userDao = userDao;
    }


    // 获取指定用户及其所有订单信息
    public LiveData<UserWithOrders> getUserWithOrders(long userId) {
        return userDao.getUserWithOrders(userId);
    }

    public long insertUser(User user) {
        // 在数据库中插入用户
        long insert = userDao.insert(user);

        return insert;
    }
    public LiveData<List<User>> searchUsers(String name, String namePinyin) {
        LiveData<List<User>> listLiveData = userDao.searchUsers(name, namePinyin);

        return listLiveData;
    }

    public LiveData<List<User>> searchUsers(String name, String nameSplit, String namePinyin, String namePinyinSplit) {
        LiveData<List<User>> listLiveData = userDao.searchUsers(name, nameSplit, namePinyin, namePinyinSplit);

        return listLiveData;
    }

}

